package threadbase.fiber;

/**
 * 线程样例
 *
 * @author xujian
 * Creation date 2024/2/19 16:28
 * @version 1.0
 */
public class JavaThread {

    public static void main(String[] args) throws InterruptedException {

        long begin = System.currentTimeMillis();
        int threadLength = 100000;
        Thread[] threads = new Thread[threadLength];
        for(int i=0;i<threadLength;i++){
            threads[i] = new Thread(() -> {
                calc();
            });
        }

        for (int i = 0; i < threadLength; i++) {
            threads[i].start();
        }
        for (int i = 0; i < threadLength; i++) {
            threads[i].join();
        }
        System.out.println("const time = "+(System.currentTimeMillis() - begin));

    }

    //200w次计算
    static void calc() {
        int result = 0;
        for (int i = 0; i < 10000; i++) {
            for (int j = 0; j < 200; j++) {
                result += i;
            }
        }
    }
}
